#!/bin/sh

# cbi - corzbax interactive - the fully interactive version
# (single-machine version)..

# basically, you can choose whether to gzip at this time, or not.

# note: this script is very immature. 
# please report any bugs/problems. ta. corz@corzoogle.com

# prefs..
devroot="/Volumes/mac/webserv"
sitefolder="cor"
backupdir="/Users/corz/bax"
arcname="corz"
# this is the file who's content we will convert into ftp commands
logfile="/Volumes/mac/webserv/itest/mirror.log"
# end prefs

cd $devroot
echo  >> $logfile
echo "corz interactive backup script: "`date "+%Y.%m.%d-%H.%M"`.. >> $logfile
echo "corz interactive backup script - "`date "+%Y.%m.%d-%H.%M"`..

# first run.. need this or else you get an error..
# "tar: Cowardly refusing to create an empty archive" (!)

if ! [ -e $backupdir/$arcname.tar ];then
	echo "creating initial 'base' archive.."
	echo "creating archive (base - no logging for this) .." >> $logfile
	tar --verify -cSf $backupdir/$arcname.tar $sitefolder > /dev/null
fi

echo "syncing backup archive.."
echo "creating archive (sync) .." >> $logfile
tar -uvSf $backupdir/$arcname.tar $sitefolder >> $logfile

echo 
echo "do you want a gzip backup of the current archive? (y/n)"
read input

if [ $input == "y" ]; then
	echo "gzipping backup archive.."
	echo "creating archive (gzipping) .." >> $logfile
	gzip -c9 $backupdir/$arcname.tar > $backupdir/`date "+%m.%d.%y-%H.%M"`_$arcname.org.tar.gz
fi

echo "backup script completes .." >> $logfile
echo  >> $logfile
echo "corz interactive backup script completed"

exit 0

# fin